<template>
	<el-dialog title="付款对话框" v-model="visible" width="600px" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="付款凭证" prop="voucherNo">
						<el-input v-model="form.voucherNo" placeholder="付款凭证" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="付款金额" prop="amount">
						<el-input v-model="form.amount" placeholder="付款金额" clearable type="number">
							<template #append>
								元
							</template>
						</el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="付款日期" prop="payableTime">
						<el-date-picker v-model="form.payableTime" placeholder="付款日期" type="date" value-format="YYYY-MM-DD" style="width: 100%;"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="付款方式" prop="payeeType">
						<sc-select v-model="form.payeeType" :params="{code:'payeeType'}" :apiObj="$API.system.sysDic.getSysDicByCode" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="付款种类" prop="payReceivedType">
						<sc-select v-model="form.payReceivedType" :params="{code:'payReceivedType'}" :apiObj="$API.system.sysDic.getSysDicByCode" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="付款人" prop="payer">
						<select-user-dialog v-model:accountId="form.payer" :mode="false"/>
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="备注">
				<el-input v-model="form.remark" placeholder="付款备注" maxlength="380" clearable type="textarea"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>

</template>
<script>
import selectUserDialog from "@/views/module/selectUserDialog";
export default {
	emits: ['success', 'closed'],
	components: {
		selectUserDialog,
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			isShowMsg:false,
			form: {
				payableId:"",
				amount:0,
				payer:'',
				payableTime: '',
				payeeType: '1',
				payReceivedType:'',
				voucherNo:'',
				remark: '',
			},
			rules: {
				payableTime: [
					{required: true, message: '付款时间不能为空'}
				],
				payer: [
					{required: true, message: '付款人不能为空',trigger: 'change'}
				],
				payReceivedType: [
					{required: true, message: '付款种类不能为空',trigger: 'change'}
				],
				amount: [
					{required: true, message: '付款金额不能为空'}
				],
				voucherNo:[
					{required: true, message: '付款凭证不能为空'}
				]
			}
		}
	},
	mounted() {
	},
	methods: {
		open(mode = 'add') {
			this.visible = true;
			return this
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					let res = await this.$API.finance.contract.insertContractPayableRecord.post(this.form);
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			this.form.payableId = data.payableId
		},
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
